import { successMsg2, errorMsg2 } from './common'
import { ipcRenderer } from 'electron'

/**
 * 监听
 * @param settingForm
 * @param t
 */
const listener = (settingForm, t) => {
  ipcRenderer.removeAllListeners('showMsg')
  ipcRenderer.on('showMsg', (e, param) => {
    if (param.suc) {
      successMsg2(t('optOk'))
    } else {
      errorMsg2(t('optErr'))
      settingForm.current.setFieldValue('startup', param.lastVal)
    }
  })

  ipcRenderer.removeAllListeners('isAutoLaunch')
  ipcRenderer.on('isAutoLaunch', (e, autoLaunch) => {
    settingForm.current.setFieldValue('startup', autoLaunch)
  })
}

export { listener }
